<template>
	<view>
		<view>
			<!-- <input type="text" v-model="name" placeholder="请输入">
			
			<view class="yes" @tap="handleClickYes">确定</view> -->
			<input type="text" placeholder="请输入补贴类型名称" v-model="name" class="ipt-source">

			<!-- <view class="yes" >确定</view> -->
			<view class="btn-confirm" @tap="handleClickYes">确定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				name: '',
				msg: '',
				changeId: '',
			}
		},
		onLoad(option) {
			if (option.item) {
				let list = JSON.parse(option.item)
				this.name = list.name;
				this.changeId = list.id;
			}
		},
		methods: {
			// 取token
			getToken() {
				try {
					const value = uni.getStorageSync('login_key');
					if (value) {
						this.token = value;
					}
				} catch (e) {
					// error
				}
			},
			// 点确定发请求
			async handleClickYes() {
				var pages = getCurrentPages();
				var currPage = pages[pages.length - 1]; //当前页面
				var prevPage = pages[pages.length - 2]; //上一个页面
				//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
				prevPage && prevPage.setData && prevPage.setData({
					isDoRefresh: true
				});
				this.getToken()
				// 发请求
				let url = this.ServicesApi.addSubsidy;
				let data = {
					name: this.name,
					id: this.changeId || '', //有值就是修改，没值就是新增
				};
				if (!this.name) {
					return uni.showToast({
						icon: 'none',
						title: '请输入补贴类型名称'
					});
				}
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					uni.showToast({
						icon: 'none',
						title: result.msg,
					});
					setTimeout(() => {
						uni.navigateBack({
							delta: 1,
							animationType: 'pop-out',
							animationDuration: 200
						});
					}, 1500);
				} else {
					uni.showToast({
						icon: 'none',
						title: result.msg,
					});
				}
			}
		},
		mounted() {

		}
	}
</script>

<style scoped lang="stylus">
	.msg {
		height: 30upx;
		font-size: 28upx;
		color: red;
	}

	.ipt-source {
		height: 110upx;
		background: #fff;
		padding: 0 40upx;
		font-size: 32upx;
	}

	.btn-confirm {
		height: 76upx;
		width: 440upx;
		background: linear-gradient(270deg, rgba(0, 106, 231, 1) 0%, rgba(66, 157, 255, 1) 100%);
		color: #fff;
		font-size: 32upx;
		text-align: center;
		line-height: 76upx;
		margin: 80upx auto;
	}
</style>
